<%@ include file="/taglibs.jsp" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<head>
		<title>北京邮电大学学生党员在线学习中心</title>

		<link href="${ctx}/css/pagination.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="${ctx }/ckeditor/ckeditor.js"></script>
		<script type="text/javascript">
		  function new_topic()
	      {
			 try
			 { 
			   var title = document.getElementById("title");
			   var editor_data = CKEDITOR.instances.content.getData();
			   var branch = document.getElementById("secondPa");
			   var adminLevel = <%=session.getAttribute("level")%>;
			   if(title.value.replace(/(^\s*)/g, "") == "")
			   {
			       alert("请输入标题!");
			       title.focus();
			       return false;
			   }
			   
			   if(editor_data==null || editor_data==""){
					alert("请输入发布的内容");
					CKEDITOR.instances.content.focus();
					return false;
				}
			   
			   if(adminLevel == 3 && branch.value == -1)
			   {
			       alert("请选择党支部!");
			       return false;
			   }
			   
			   }
			   catch(e)
			   {
			       alert(e);
			       return false;
			   }
	    }
    </script>
    
    <script type="text/javascript">
        
	   var xmlHttp;
	  
		 function changeSecond(value) {
	       if(value != -1) {
               var uri = "AdminAction_getChildrenPaByParentId?parentId=" + escape(value);
               if(window.XMLHttpRequest) {
                   xmlHttp = new XMLHttpRequest();
               } else {
                   try {
                       xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                   } catch(e) {
                       try {
                           xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                       } catch(e) {
                           alert("不能创建XMLHttpRequest对象!!!");
                           return;
                   }
               }
           }
                xmlHttp.open("post", uri, true);
                xmlHttp.onreadystatechange = handleResponse;
                xmlHttp.send(null);
       } else {
    	    clearElement1("secondPa");
       }
     }
		 
		  function handleResponse() {
           if(xmlHttp.readyState == 4) {
               if(xmlHttp.status == 200) {
                   updateSelect("secondPa");
                   var idList = xmlHttp.responseXML.getElementsByTagName("id"); 
                   if(idList.length < 1) {
                	   clearElement1("secondPa");
                   } else {
                	   ;
                   }
               }
           }
       }
		  
		  
	  //根据返回的结果更新党支部信息
		function  updateSelect(id) {
			var selectList = document.getElementById(id);
			var idList = xmlHttp.responseXML.getElementsByTagName("id");
			var nameList = xmlHttp.responseXML.getElementsByTagName("branchName");
			if(idList.length > 0) {
				document.getElementById(id).style.display="inline";
				clearElement(id);
				selectList.options.add(new Option('请选择党支部', '-1'));
				for(var i = 0; i<idList.length; i++) {
					selectList.options.add(new Option(nameList[i].firstChild.nodeValue, idList[i].firstChild.nodeValue));
				}
			}
			else{
				document.getElementById(id).style.display="none";
			}
			
		}
		
		 //清除元素
		function clearElement(id) {
			document.getElementById(id).length = 0;
		}
		 
		//当只有一级或者两级党组织时，需要清理遗留的其他党组织信息
		function clearElement1(id) {
		   var selectList = document.getElementById(id);
    	   clearElement(id);
    	   selectList.options.add(new Option('请选择党支部', '-1'));
    	   document.getElementById(id).style.display="none";
		 }
	
	</script> 
</head>
<div id="nav_bar">
    <img id="nav_bar_left" src="../../../styles/nav_bar_left.png" alt=""/>
    <div id="welcome_label">欢迎您，&nbsp;<s:property value="#session.session_user.adminName" />!</div>
    <img id="nav_bar_seperator" src="../../../styles/nav_bar_seperator.png" alt=""/>
    <div id="nav_location">
        <img id="nav_bar_point" src="../../../styles/nav_bar_point.png" alt="" />
        <div id="nav_cur_location">当前位置：&nbsp;<a href="${ctx}/Admin_branchManageAction_manageBranch">党组织管理</a>&nbsp;&nbsp;>&nbsp;&nbsp;
         <s:if test="#request.flag==1">
        	<a href="${ctx }/Admin_MyBranchAction_manageBranchNotice">支部公告管理</a>&nbsp;&nbsp;>&nbsp;&nbsp;<span style="color:black;">发布新支部公告</span>
        </s:if>
        <s:elseif test="#request.flag==2">
        	<a href="${ctx }/Admin_MyBranchAction_manageBranchActivity">支部活动管理</a>&nbsp;&nbsp;>&nbsp;&nbsp;<span style="color:black;">发布新支部活动</span>
        </s:elseif>
        </div>
    </div>
    <img style="float:right; width:5px;" src="../../../styles/nav_bar_right.png" alt=""/>
    <a id="nav_logout" href="${ctx}/logoutAction_adminLogout">[安全退出]</a>
</div>

<div style="clear:both; height:20px;">&nbsp;</div>

<div style="margin-left:auto; margin-right:auto; width:96%;">
		<s:form  action="Admin_MyBranchAction_saveBranchActivity" method="post" theme="simple" onsubmit="return new_topic();">
		<table>
			<tr>
				<td >
				<b>标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
				</td>
 				<td >
 				<input type="text" name="title" id="title"  maxlength="60" style="width:99%" value=""/>
				</td>
			</tr>
			<tr>
				<td>
				<b>内&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;容：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
				</td>
 				<td >
 					<ckfinder:setupCKEditor editor="content" basePath="ckfinder"/>
			        <ckeditor:editor basePath="ckeditor/" editor="content" value="请在此处填写内容，内容不能为空" /> 					
				</td>
			</tr>
			<s:if test="#session.session_user.adminLevel != 1">
			<tr>
				<td><b>所属党支部:</b></td>
				<td>
					
					<s:select id="firstPa" list="firstPaList" listKey="id" listValue="branchName" name="firstPa" headerKey="-1" headerValue="请选择党委"   onchange="changeSecond(this.value);" />
					<s:if test="#request.secondPa != -1">
						<s:select id="secondPa" list="secondPaList" listKey="id" listValue="branchName" name="secondPa" headerKey="-1" headerValue="请选择支部" />
					</s:if>
					<s:else>
						<s:select id="secondPa" list="secondPaList" listKey="id" listValue="branchName" name="secondPa" headerKey="-1" headerValue="请选择支部"  style="display:none;"/>
					</s:else>
					<font color=red>*</font>
					
				</td>
			</tr>
			</s:if>
		</table>
		<br>
		<div style="text-align:center;">
		<input id="posttopic" name="posttopic" type="submit" value="发布" class="input-button" />&nbsp;&nbsp;&nbsp;&nbsp;
		<input id="history" name="history" type="button" class="input-button" value="返回"  onclick="window.location.href='javascript:history.go(-1);'"/>
		</div>
		</s:form>
</div>
